package com.jxt.myjxtmanager.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.jxt.myjxtmanager.db.dao.Message_TaskDao;
import com.jxt.myjxtmanager.db.dao.SaleUserDao;
import com.jxt.myjxtmanager.db.dao.StudentDao;
import com.jxt.myjxtmanager.db.dao.SubjectDao;

import de.greenrobot.dao.AbstractDaoMaster;
import de.greenrobot.dao.identityscope.IdentityScopeType;


// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.

/**
 * Master of DAO (schema version 1): knows all DAOs.
 */
public class DaoMaster extends AbstractDaoMaster {
    public static final int SCHEMA_VERSION = 1;

    /**
     * Creates underlying database table using DAOs.
     */
    public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {
        SaleUserDao.createTable(db, ifNotExists);
        Message_TaskDao.createTable(db, ifNotExists);
        StudentDao.createTable(db, ifNotExists);
        SubjectDao.createTable(db, ifNotExists);
    }

    /**
     * Drops underlying database table using DAOs.
     */
    public static void dropAllTables(SQLiteDatabase db, boolean ifExists) {
        SaleUserDao.dropTable(db, ifExists);
        Message_TaskDao.dropTable(db, ifExists);
        StudentDao.createTable(db, ifExists);
        SubjectDao.createTable(db, ifExists);
    }

    public static abstract class OpenHelper extends SQLiteOpenHelper {

        public OpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory, SCHEMA_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
            createAllTables(db, false);
        }
    }

    /**
     * WARNING: Drops all table on Upgrade! Use only during development.
     */
    public static class DevOpenHelper extends OpenHelper {
        private OnDbUpgrade onDbUpgrade = null;

        public DevOpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
            dropAllTables(db, true);
            onCreate(db);
        }

        public void setOnUpgrade(OnDbUpgrade onDbUpgrade) {
            this.onDbUpgrade = onDbUpgrade;
        }

        public interface OnDbUpgrade {
            void onDbUpgrade(SQLiteDatabase db, int migrateVersion);
        }
    }

    public DaoMaster(SQLiteDatabase db) {
        super(db, SCHEMA_VERSION);
        registerDaoClass(SaleUserDao.class);
        registerDaoClass(Message_TaskDao.class);
        registerDaoClass(StudentDao.class);
        registerDaoClass(SubjectDao.class);
//        registerDaoClass(CountryDao.class);
    }

    public DaoSession newSession() {
        return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
    }


    public DaoSession newSession(IdentityScopeType type) {
        return new DaoSession(db, type, daoConfigMap);
    }

}
